﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TB_CS.ID_Manage
{
    public partial class User_Manage : Form
    {
        public User_Manage()
        {
            InitializeComponent();
        }
        private static string User_Name = "";
        private void User_Manage_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource= Class.SysInfo.WSSUSER.GET_USER_LIST(Convert.ToInt32(Class.SysInfo.INFO_Seller_ID), "").Tables[0];
            groupBox3.Enabled = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("请输入要创建的用户名", "警告");
                textBox1.Focus();
            }
            else if (Class.SysInfo.WSSUSER.GET_USER_COUNT(Convert.ToInt32(Class.SysInfo.INFO_Seller_ID), textBox1.Text.Trim().ToString()) != 0)
            {
                MessageBox.Show("该用户名已存在", "警告");
                textBox1.Text = "";
                textBox1.Focus();
            }
            {
                Class.SysInfo.WSSUSER.INSERT_USER(Convert.ToInt32(Class.SysInfo.INFO_Seller_ID),
                    textBox1.Text.Trim().ToString(), "123123");
                MessageBox.Show("登录账号：" + textBox1.Text.Trim().ToString() + "已成功创建，默认登录密码：123123，请登陆后及时修改密码");
                dataGridView1.DataSource = Class.SysInfo.WSSUSER.GET_USER_LIST(Convert.ToInt32(Class.SysInfo.INFO_Seller_ID), "").Tables[0];
            }
            
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            groupBox3.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString() + " 状态操作";
            User_Name = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
            button2.Text = "停用账户："+dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
            button3.Text = "恢复账户：" + dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
            groupBox3.Enabled = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Class.SysInfo.WSSUSER.UPDATE_USER_TYPE(
                Convert.ToInt32(Class.SysInfo.INFO_Seller_ID.ToString()),
                User_Name, "STOP");
            dataGridView1.DataSource = Class.SysInfo.WSSUSER.GET_USER_LIST(Convert.ToInt32(Class.SysInfo.INFO_Seller_ID), "").Tables[0];
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Class.SysInfo.WSSUSER.UPDATE_USER_TYPE(
                Convert.ToInt32(Class.SysInfo.INFO_Seller_ID.ToString()),
                User_Name, "available");
            dataGridView1.DataSource = Class.SysInfo.WSSUSER.GET_USER_LIST(Convert.ToInt32(Class.SysInfo.INFO_Seller_ID), "").Tables[0];
        }
    }
}
